<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>

  <body>
    <input type="text" />
    <script>
      //获取输入框
      var search = document.querySelector("input");
      // 键盘按键弹起事件
      document.addEventListener("keyup", function (e) {
        // console.log(e.keyCode);
        //a建的ASCII码值为65
        //判断用户是否按下a键并弹起
        if (e.keyCode === 65) {
          //聚焦到输入框
          search.focus();
        }
      });
    </script>
  </body>
</html>
